import { ajax } from '/ajax';

Page({
  data: {
    // 普通支付1或预授权支付2
    payStatus:'',
    // 订单金额
    total_amount:'',
    // 订单号
    out_trade_no:'',
    // 退款金额
    refundPrice:'',
    // 备注
    remark:'',
  },
  // 点击全额
  allAmount() {
    let that = this;
    that.setData({refundPrice: that.data.total_amount})
  },
  // 获取退款金额
  getInputValue(e) {
    this.setData({ refundPrice: e.detail.value })
  },
  // 获取备注
  getTextareaValue(e) {
    console.log(e.detail.value)
    this.setData({ remark: e.detail.value })
  },
  // 退款
  async refund(){
    let that = this;
    console.log('退款')
    let parame = {
      token: my.getStorageSync({key: 'token'}).data,
      out_trade_no: that.data.out_trade_no,
      devices: 'QCF420190927117689',
      type: 0,
      remark: that.data.remark,
      pay_password: 123456,
      amount: that.data.refundPrice
    }
    let refundData = await ajax('/SmallAppSmileRefund', parame);
    console.log(refundData)
    if(refundData.data.status === 1 ) {
      my.showToast({
        type: 'success',
        content:'退款成功',
        success: (res) => {
          my.redirectTo({url: '../record-home/record-home'});
        },
      });
    }else{
      my.alert({
        content: refundData.data.msg,
        success: (res) => {
          // my.redirectTo({url: '../record-home/record-home'});
        },
      });
    }
  },
 
  onLoad(option) {
    console.log(option)
    this.setData({
      payStatus: option.payStatus,
      total_amount: option.total_amount,
      out_trade_no: option.out_trade_no 
    })
  },
  onShow() {
    
  },
});
